package com.studentmanage.manage_student.dao;

import com.studentmanage.framework.domain.base.StudentExt;
import com.studentmanage.framework.domain.base.request.QueryStudentRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StudentExtMapper {
    String QUERY_CODE_SQL=" <if test=\"studentName != null and studentName != ''\"> " +
            "and stu.name like \"%\"#{studentName}\"%\" " +
            "</if> " +
            "<if test=\"collegeName != null and collegeName != ''\"> " +
            "and college.name like \"%\"#{collegeName}\"%\" " +
            "</if> " +
            "<if test=\"className != null and className != ''\"> " +
            "and class.name like \"%\"#{className}\"%\" " +
            "</if> " +
            "<if test=\"id != null and id != ''\"> " +
            "and stu.id like \"%\"#{id}\"%\" " +
            "</if> " +
            "<if test=\"specializeName != null and specializeName != ''\"> " +
            "and specialize.name like \"%\"#{specializeName}\"%\" " +
            "</if>";
    String QUERY = "<if test=\"studentName != null and studentName != ''\"> "+
            "and student.name like \"%\"#{studentName}\"%\" </if> ";

    @Select({"<script> SELECT stu.id, stu.name, stu.sex, stu.birthday, stu.entrancetime, stu.native as homeNative, stu.address, stu.telephone, stu.idnum, stu.national, stu.status, " +
            "class.name as className, specialize.name as specializeName, college.name as collegeName " +
            "FROM student stu, class, college, specialize WHERE " +
            "stu.classid = class.id "+
            "AND class.specializeid = specialize.id " +
            "AND specialize.collegeid = college.id" + QUERY_CODE_SQL + "limit #{page},#{size} </script>"})
    public List<StudentExt> findStudentList(QueryStudentRequest queryStudentRequest);

    @Select({"<script> SELECT count(stu.name) " +
            "FROM student stu, class, college, specialize WHERE " +
            "stu.classid = class.id "+
            "AND class.specializeid = specialize.id " +
            "AND specialize.collegeid = college.id" + QUERY_CODE_SQL + "</script>"})
    public Integer getTotalNum(QueryStudentRequest queryStudentRequest);

}
